home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / bserverdir / sources / clients / mandelbrot.c < prev    next >
C/C++ Source or Header  |  1994-11-25  |  3KB  |  164 lines

  1. ;/*
  2. sc mandelbrot.c DATA=FAR NMINC STRMERGE NOSTKCHK IGNORE=73 STRUCTUREEQUIVALENCE NOSTDIO
  3. slink from LIB:c.o mandelbrot.o to //Clients/Mandelbrot LIB LIB:scm.lib LIB:sc.lib LIB:amiga.lib /lib/client.lib SC SD STRIPDEBUG NOICONS
  4. delete mandelbrot.o
  5. quit
  6.  
  7.  Mandelbrot 1.2  (Client for BServer)
  8.  
  9.  Copyright © 1994 Luca Viola & Stefano Reksten of 3AM - The Three Amigos!!!
  10.  All rights reserved.
  11. */
  12.  
  13. #include <exec/types.h>
  14. #include <intuition/intuition.h>
  15.  
  16. #include <clib/exec_protos.h>
  17. #include <clib/intuition_protos.h>
  18. #include <clib/graphics_protos.h>
  19. #include <stdlib.h>
  20. #include <math.h>
  21. #include <time.h>
  22.  
  23. #include "/include/client.h"
  24.  
  25. struct IntuitionBase *IntuitionBase;
  26. struct GfxBase *GfxBase;
  27. struct Library *BitMapBase;
  28.  
  29. struct DisplayIDInformation *dinfo;
  30. UBYTE command;
  31. BOOL stillBlanking;
  32.  
  33. #define XOFF        0
  34. #define YOFF         0
  35.  
  36. #define    RISX        240
  37. #define    RISY        240
  38. #define    PLANES        4
  39. #define    MAXITER        32
  40. #define    COLORS        (1 << PLANES)
  41.  
  42. /* function prototypes */
  43.  
  44. void Mandel( void );
  45. void DrawMandel( void );
  46.  
  47. /*  Intuition global  structures */
  48.  
  49. struct IntuitionBase *IntuitionBase;
  50. struct GfxBase *GfxBase;
  51. struct Screen *thescreen;
  52. struct RastPort *rport;
  53. struct ViewPort vport;
  54. struct BitMap *bitmap;
  55. ULONG *table;
  56.  
  57. UWORD colors[]=
  58. {
  59.     0x0000, 0x011F, 0x022E, 0x033D, 0x044C, 0x055B, 0x066A, 0x0779,
  60.     0x0888, 0x0997, 0x0AA6, 0x0BB5, 0x0CC4, 0x0DD3, 0x0EE2, 0x0FF1
  61. };
  62.  
  63.  
  64. void Mandel()
  65. {
  66. struct Rectangle *rect = GETTXTOSCANRECT(dinfo);
  67.  
  68. if ( thescreen = (struct Screen *)OpenScreenTags( NULL,
  69.         SA_Left, (RECTANGLEWIDTH(rect) - RISX)>>1,
  70.         SA_DisplayID, DISPLAYID(dinfo),
  71.         SA_Width, RISX,
  72.         SA_Height, RISY,
  73.         SA_Depth, PLANES,
  74.         SA_Quiet, TRUE,
  75.         SA_Overscan, OSCAN_TEXT,
  76.         TAG_DONE ) )
  77.     {
  78.     rport=&(thescreen->RastPort);
  79.     vport=thescreen->ViewPort;
  80.     LoadRGB4( &vport,colors,COLORS );
  81.     DrawMandel();
  82.     CloseScreen( thescreen );
  83.     }
  84. else
  85.     SendClientMsg( ACTION_FAILED );
  86. }
  87.  
  88.  
  89. void DrawMandel()
  90. {
  91.     double quadsize;
  92.     double temp,xr,yr,d,vx,vy,x1real,y1imm,x2real,y2imm,gapx,gapy;
  93.     UWORD loop,x,y,risx,risy;
  94.  
  95.     SpritesOff();
  96.  
  97.     srand48( (unsigned int)time( NULL ) );    
  98.     quadsize = 3.4 * drand48();
  99.     x1real=-2.2 * drand48();
  100.     x2real=x1real + quadsize;
  101.     y1imm=-1.7 * drand48();
  102.     y2imm=y1imm + quadsize;
  103.  
  104.     risx=RISX;
  105.     risy=RISY;
  106.     gapx=(x2real-x1real)/risx;
  107.     gapy=(y1imm-y2imm)/risy;
  108.     vy=y2imm;
  109.  
  110.     stillBlanking = TRUE;
  111.  
  112.     for ( y=0; y<=RISY; y++ )
  113.     {
  114.         vy=vy+gapy;
  115.         vx=x1real;
  116.         for( x=0; x<RISX && stillBlanking; x++ )
  117.         {
  118.             vx=vx+gapx;
  119.             xr=0;yr=0;
  120.             loop=0;
  121.  
  122.             do
  123.             {
  124.                 loop++;
  125.                 temp=((xr*xr)-(yr*yr))+(vx);
  126.                 yr=((2.0F*xr)*yr)+vy;
  127.                 xr=temp;
  128.                 d=(xr*xr)+(yr*yr);
  129.                 if (d > 4.0F)
  130.                 {
  131.                     SetAPen( &(thescreen->RastPort), loop%COLORS+1 );
  132.                     WritePixel( &(thescreen->RastPort), x, y );
  133.                       loop=MAXITER;
  134.                 }
  135.             stillBlanking = STILL_BLANKING;
  136.             }
  137.             while(loop!=MAXITER && stillBlanking );
  138.         }
  139.     }
  140.  
  141.     if ( stillBlanking )
  142.         (void)WaitServerCommand();
  143.  
  144.     SpritesOn();
  145. }           
  146.  
  147.  
  148. void __main( char *line )
  149. {
  150. if ( IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", 37L ) )
  151.     {
  152.     if ( GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", 37L ) )
  153.         {
  154.         if ( dinfo = OpenCommunication() )
  155.             {
  156.             Mandel();
  157.             CloseCommunication( dinfo );
  158.             }
  159.         CloseLibrary( (struct Library *)GfxBase );
  160.         }
  161.     CloseLibrary( (struct Library *)IntuitionBase );
  162.     }
  163. }
  164.